﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Volume_Resource_Management
{
    public partial class frmPrintSchedule : Form
    {
        private System.Drawing.Printing.PrintDocument docToPrint =
        new System.Drawing.Printing.PrintDocument();

        string storenumber;
        string date;

        public frmPrintSchedule(string sno, string dte)
        {
            InitializeComponent();
            storenumber = sno;
            date = dte;
        }

        private void frmPrintSchedule_Load(object sender, EventArgs e)
        {
            label1.Text = "Logistics Schedule For " + date;

            dataGridView1.DataSource = databaseAccessability.getAllWorkingEmployees(storenumber, date);
            dataGridView1.Columns["workDate"].DisplayIndex = 0;
            dataGridView1.Columns["ID"].Visible = false;
            dataGridView1.Columns["storeNo"].Visible = false;
            dataGridView1.Columns["sm"].Visible = false;
            dataGridView1.Columns["employeeName"].Width = 200;
            dataGridView1.Columns["workTime"].Width = 150;
            dataGridView1.Columns["department"].Width = 200;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells[5].Value.ToString() == "0")
                {
                    if (dataGridView1.Rows[i].Cells[6].Value.ToString() == "1")
                    {
                        dataGridView1.Rows[i].Cells[5].Value = "Self Serve";
                    }
                    else
                    {
                        dataGridView1.Rows[i].Cells[5].Value = "Full Serve";
                    }
                }
                else
                {
                    switch (dataGridView1.Rows[i].Cells[5].Value.ToString())
                    {
                        case "01":
                            dataGridView1.Rows[i].Cells[5].Value = "Living";
                            break;

                        case "02":
                            dataGridView1.Rows[i].Cells[5].Value = "Storage";
                            break;

                        case "03":
                            dataGridView1.Rows[i].Cells[5].Value = "Work Ikea";
                            break;

                        case "04":
                            dataGridView1.Rows[i].Cells[5].Value = "Bedrooms";
                            break;

                        case "06":
                            dataGridView1.Rows[i].Cells[5].Value = "BathShop";
                            break;

                        case "07":
                            dataGridView1.Rows[i].Cells[5].Value = "Kitchens";
                            break;

                        case "08":
                            dataGridView1.Rows[i].Cells[5].Value = "Dining";
                            break;

                        case "09":
                            dataGridView1.Rows[i].Cells[5].Value = "Kids";
                            break;

                        case "10":
                            dataGridView1.Rows[i].Cells[5].Value = "Lighting";
                            break;

                        case "11":
                            dataGridView1.Rows[i].Cells[5].Value = "Bed Textiles";
                            break;

                        case "12":
                            dataGridView1.Rows[i].Cells[5].Value = "Home Textiles";
                            break;

                        case "13":
                            dataGridView1.Rows[i].Cells[5].Value = "Rugs";
                            break;

                        case "14":
                            dataGridView1.Rows[i].Cells[5].Value = "Cooking";
                            break;

                        case "15":
                            dataGridView1.Rows[i].Cells[5].Value = "Eating";
                            break;

                        case "16":
                            dataGridView1.Rows[i].Cells[5].Value = "Home Decoration";
                            break;

                        case "17":
                            dataGridView1.Rows[i].Cells[5].Value = "Outdoor";
                            break;

                        case "18":
                            dataGridView1.Rows[i].Cells[5].Value = "Home Organisation";
                            break;

                        case "19":
                            dataGridView1.Rows[i].Cells[5].Value = "Secondary Storage";
                            break;

                        case "92":
                            dataGridView1.Rows[i].Cells[5].Value = "Family";
                            break;

                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            docToPrint.PrintPage += printDoc;

            printDialog1.Document = docToPrint;

            DialogResult result = printDialog1.ShowDialog();

            // If the result is OK then print the document. 
            if (result == DialogResult.OK)
            {
                panel1.Height = 1020;
                docToPrint.Print();
            }
            panel1.Height = 759;
        }

        private void printDoc(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap bm = new Bitmap(panel1.Width, panel1.Height);
            panel1.DrawToBitmap(bm, new Rectangle(0, 0, 2480, 3508));
            e.Graphics.DrawImage(bm, 75, 10);
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

        }
    }
}
